import { z } from "zod";
import path from "path";
import { fileURLToPath } from "url";
import { getComprehensiveThinkSolutionPrompt } from "../../prompts/index.js";
import { getMemoryDir } from "../../utils/paths.js";

// 全面思考并搜索解决方案工具
// Comprehensive Think Solution Tool
export const comprehensiveThinkSolutionSchema = z.object({
  problemAnalysis: z
    .string()
    .min(20, {
      message: "问题分析结果不能少于20个字符，请提供更完整的分析内容",
    })
    .describe("来自深入分析阶段的完整问题分析结果"),
  solutionTypes: z
    .array(z.enum(['traditional', 'innovative', 'hybrid', 'alternative']))
    .optional()
    .default(['traditional', 'innovative'])
    .describe("解决方案类型选择列表"),
  searchStrategy: z
    .enum(['focused', 'broad', 'layered', 'comprehensive'])
    .optional()
    .default('layered')
    .describe("搜索策略选择"),
  resourceConstraints: z
    .object({
      time: z.enum(['tight', 'moderate', 'flexible']).optional(),
      budget: z.enum(['limited', 'moderate', 'sufficient']).optional(),
      technical: z.enum(['basic', 'intermediate', 'advanced']).optional()
    })
    .optional()
    .describe("资源约束条件")
});

export async function comprehensiveThinkSolution({
  problemAnalysis,
  solutionTypes = ['traditional', 'innovative'],
  searchStrategy = 'layered',
  resourceConstraints = {}
}: z.infer<typeof comprehensiveThinkSolutionSchema>) {
  // 获取基础目录路径
  // Get base directory path
  const __filename = fileURLToPath(import.meta.url);
  const __dirname = path.dirname(__filename);
  const PROJECT_ROOT = path.resolve(__dirname, "../../..");
  const MEMORY_DIR = await getMemoryDir();

  // 使用prompt生成器获取最终prompt
  // Use prompt generator to get the final prompt
  const prompt = await getComprehensiveThinkSolutionPrompt({
    problemAnalysis,
    solutionTypes,
    searchStrategy,
    resourceConstraints,
    memoryDir: MEMORY_DIR,
  });

  return {
    content: [
      {
        type: "text" as const,
        text: prompt,
      },
    ],
  };
}